﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace smartGardenWebService
{
    public class webServiceDataDeal
    {
        string sqlConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["smartGardenConnectinString"].ConnectionString;
        public string insertDb(string sqlComm)
        {
            string msg = "插入数据库失败！";             //普通插入时，提示
            if (sqlComm.Contains("autoModeValue"))      //自动模式，设定范围值时，提示
            {
                msg = "设置范围值失败,请检查范围值是否正确设置！";
            }
            if (sqlComm.Contains("orderReceive"))      //接收指令时，提示
            {
                msg = "接收指令，插入数据库失败！";
            }
            if (sqlComm.Contains("dealReceive"))       //接收指令截取，提示
            {
                msg = "接收指令截取，插入数据库失败！";
            }
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = sqlConnStr;
            try
            {
                conn.Open();
            }
            catch
            {
                return "数据库打开失败";
            }
            SqlCommand sqlCommand = new SqlCommand(sqlComm, conn);
            try
            {
                sqlCommand.ExecuteNonQuery();
                conn.Close();
            }
            catch
            {
                return msg;
            }
            return "";
        }
    }
}